/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rultax.neural;

/**
 * 
 * @author scottw
 */
public abstract class AbstractNeuron {
    public abstract double getOutput();
    public abstract void setOutput(double output);
    public abstract double[] getInput();
    public abstract double[] getWeights();
    public abstract double getResultantInputSignal();
    protected abstract void setResultantInputSignal(double resultantInputSignal);
    public abstract double applyActivationFunction();
    
    protected double calculateResultantInputSignal() throws InvalidNeuronConfigException{
	
	if(getInput().length != getWeights().length)
	    throw new InvalidNeuronConfigException("Input count and weight count must be the same");
	
	double result = 0;
	
	for(int i = 0; i < getInput().length; i++){
	    result += getInput()[i] * getWeights()[i];
	}
	
	setResultantInputSignal(result);
	return result;
    }
    
    public double process() throws InvalidNeuronConfigException{	
	double resultantInputSignal = calculateResultantInputSignal();
	double activationOutput = applyActivationFunction();
	setOutput(activationOutput);
	return activationOutput;
    }
}
